﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Homework1_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            insertComboItem();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            //获取当前选中的值
            string itemText = cb.SelectedItem as string;
            if (!string.IsNullOrWhiteSpace(itemText) && lblResult != null)
            {
                //显示当前选择项的内容
                this.lblResult.Text = string.Format("您选择了：{0}项。", itemText);
            }
        }
        private void insertComboItem()
        {
            lblResult.Items.Add("+");
            lblResult.Items.Add("-");
            lblResult.Items.Add("*");
            lblResult.Items.Add("/");
            lblResult.Items.Add("%");

            //默认选择第一项
            lblResult.SelectedIndex = 0;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {


        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string s1 = textBox1.Text;
            string s2 = textBox2.Text;
            float a1 = float.Parse(s1);
            float a2 = float.Parse(s2);
            string op = lblResult.Text;
            float res = 0;
            switch (op)
            {
                case "+":
                   res=(a1 + a2);
                    break;
                case "-":
                    res=(a1 - a2);
                    break;
                case "*":
                    res=(a1 * a2);
                    break;
                case "/":
                    res=(a1 / a2);
                    break;
                default:label2.Text="格式错误！"; res = 0; break;
            }
            label2.Text = res.ToString();
        }
    }
}
